<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
<title>扫码登录</title>
<link href="style/login.css" rel="stylesheet" type="text/css" />
<link href="css/vant.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="login_boss/js/js.js"></script>
<script src="js/vue/vue.js"></script>
<script src="js/vue/axios.js"></script>
<script src="js/vue/qs.js"></script>
<script src="js/vue/MD5.js"></script>
<script src="js/vue/vant.js"></script>
<style>
    .dlcg{
        text-align: center;
    }
    .dlcg img{
        width: 100px;
        height: 100px;
        margin-bottom: 28px;
        margin-top:132px;
        display: inline-block;
    }
    .dlcg p{
       font-size: 16px;
       font-weight: 600;
       height:25px;
       font-size:18px;
       color:rgba(42,42,42,1);
       line-height:25px;
    }
</style>
</head>
<body>
<div id="app">
    <div v-show="isShow" class="main">
        <div class="ve_title">请先绑定手机号码</div>
        <div class="login_o" id="phone_login">
            <div class="login_text">手机号</div>
            <div class="login_input">
                <input v-model="from1.phone" style="font-size: 14px;" id="phone" type="text" class="phone_input" onkeyup="this.value=this.value.replace(/\D/g,'');" maxlength="11" onafterpaste="this.value=this.value.replace(/\D/g,'')" placeholder="请输入手机号码"/>
            </div>
            <div class="login_text" style="margin-top:10px">短信验证码</div>
                <div class="login_input_code"  style="padding-bottom:3px;">
                <input v-model="from1.sms_code" style="font-size: 14px;width: 50%;" id="code" type="text" class="code_input" placeholder="请输入验证码" onkeyup="this.value=this.value.replace(/\D/g,'');" maxlength="6" onafterpaste="this.value=this.value.replace(/\D/g,'')" style="width:55%;"/>
                <div class="code_getcode" @click="get_sms_code()" style="float:right;">获取验证码</div>
            </div>
        </div>
        <div class="login_but_o" @click="bingPhone">绑定手机号</div>
    </div>
    <div v-show="isSuccess" class="dlcg">
        <img src="images/dlcg.png"/>
        <p>登录成功</p>
    </div>
    <input ref="login_type" id="login_type" type="hidden" value="phone" />
    <input ref="send" id="send" type="hidden" value="60" />
</div>
</body>
<script>
var app = new Vue({
    el: '#app',
    data: {
        isShow:false,
        Scode:'',
        from1:{
            sms_code: "",
            phone: "",
            vid:'',
            action:"boss"
        },
        wxinfo:'',
        Openid:'',
        session_code:'',
        Unionid:'',
        state:'',
        isPhone:false,
        isSuccess:false
    },
    created(){
        this.setCanS()
    },
    methods: {
        //设置参数
        setCanS(){
            let Request = new Object()
            Request = GetRequest()
            this.Scode = Request['Scode']
            this.wxinfo = Request['wxinfo']
            if(this.wxinfo!=''&&this.wxinfo!=null&&this.wxinfo!=undefined){
                this.getWxlogin()
            }
           
        },
        gologins() {
            sessionStorage.setItem('logo','1')
            if(this.$refs.login_type.value=='user'){
                var obj = this;
                let password=md5(this.from.password)
                password=md5(password)
                let from = { 
                        username: this.from.username,
                        password: password,
                        vid:sessionStorage.getItem('vid'),
                        action:"boss"};
                from =JSON.stringify(from)
                let sign=md5(from)
                let params={
                    from:from,
                    sign:sign
                }
                axios.post('/mobileapi/login_staff.php?act=logingo',
                Qs.stringify(params)).then(function(response){
                    let { msg, code} = response.data
                        if (code !== 200) {
                            window.vant.Toast.fail(msg)
                        } else {
                            var data = response.data
                            console.log(data)
                            sessionStorage.setItem('vxPhone',data.data.Phone)
                            if(data.data.login_from=='BOSS'){
                                if(data.data.login_type=='2'){
                                    sessionStorage.setItem('logo','1')
                                    sessionStorage.setItem('token',data.data.Gtoken)
                                    let venueset_list=JSON.stringify(data.data.venueset_list)
                                    sessionStorage.setItem("venueset_list",venueset_list)
                                    //跳转到选择场馆页面
                                    window.location.href='selectShop.html?vid='+this.vid+''
                                }else{
                                    sessionStorage.setItem('logo','0')
                                    sessionStorage.setItem('token',data.data.Gtoken)
                                    console.log(data.data.Vid)
                                    this.vid=data.data.Vid
                                    sessionStorage.setItem('vids',this.vid)
                                    sessionStorage.setItem('vid',this.vid)
                                    let type="logo"
                                    localStorage.setItem('boss',"1")
                                    localStorage.setItem('bossvid',data.data.Vid)
                                    localStorage.setItem('bossGtoken',data.data.Gtoken)
                                    //保存登录有效期
                                    let timeLoc=new Date()
                                    localStorage.setItem('bossTime',new Date(timeLoc.getTime() + 365*24*60*60*1000))
                                    sessionStorage.setItem('type',type)
                                    window.location.href='index.html?vid='+this.vid+'&type='+type+''
                                }
                            }else{
                                window.vant.Toast("该账号无法登陆BOSS端")
                            }
                            
                        }
                    }).catch(function (error) { 
                        console.log(error); 
                });
            }else{
                this.from1.vid=sessionStorage.getItem('vid')
                let from = this.from1
                from =JSON.stringify(from)
                let sign=md5(from)
                let params={
                    from:from,
                    sign:sign
                }
                axios.post('/mobileapi/login_staff.php?act=sms_login',Qs.stringify(params)).then(data => {
                    let { msg, code} = data.data
                        if (code !== 200) {
                            window.vant.Toast.fail(msg)
                        } else {
                            var data = data.data
                            if(data.data.login_from=='BOSS'){
                                if(data.data.login_type=='2'){
                                    sessionStorage.setItem('logo','1')
                                    sessionStorage.setItem('token',data.data.Gtoken)
                                    let venueset_list=JSON.stringify(data.data.venueset_list)
                                    sessionStorage.setItem("venueset_list",venueset_list)
                                    sessionStorage.setItem('vxPhone',this.from1.phone)
                                    //跳转到选择场馆页面
                                    window.location.href='selectShop.html?vid='+this.vid+''
                                }else{
                                    sessionStorage.setItem('logo','0')
                                    sessionStorage.setItem('token',data.data.Gtoken)
                                    console.log(data.data.Vid)
                                    this.vid=data.data.Vid
                                    sessionStorage.setItem('vids',this.vid)
                                    sessionStorage.setItem('vid',this.vid)
                                    let type="logo"
                                    localStorage.setItem('boss',"1")
                                    localStorage.setItem('bossvid',data.data.Vid)
                                    localStorage.setItem('bossGtoken',data.data.Gtoken)
                                    //保存登录有效期
                                    let timeLoc=new Date()
                                    localStorage.setItem('bossTime',new Date(timeLoc.getTime() + 365*24*60*60*1000))
                                    sessionStorage.setItem('type',type)
                                    window.location.href='index.html?vid='+this.vid+'&type='+type+''
                                }
                            }else{
                                window.vant.Toast("该账号无法登陆BOSS端")
                            }
                        }
                    }).catch(function (error) { 
                        console.log(error); 
                });
            }
        },
        //获取手机验证码
        get_sms_code(){
            var send=parseInt(this.$refs.send.value);
            if(!isPoneAvailable(this.from1.phone)){
                window.vant.Toast.fail("请输入正确的手机号")
                return false;
            }
            const params={
                phone:this.from1.phone
            }
            if(send==60){
                axios.post('/mobileapi/member/login.php?act=getsms',Qs.stringify(params)).then(function(response){
                        if(response.data.code=="200"){
                            window.vant.Toast.success("短信已发，请注意查收")
                        }else{
                            window.vant.Toast.fail(response.data.msg)
                        }
                    }).catch(function (error) {
                        console.log(error)
                        window.vant.Toast.fail("短信发送失败！请确认手机号是否正确。");
                })   
                var set=setInterval(function(){
                    var send_t=--send;
                    $(".code_getcode").html(""+send_t+"秒");
                    $("#send").val(--send_t)
                }, 1000);
                setTimeout(function(){
                    $(".code_getcode").html("重新获取");
                    $("#send").val(60)
                    clearInterval(set);
                }, 60000);
            }	
        },
        //验证手机号正不争取
        isPoneAvailable($poneInput) {
            let params={
                phone:$poneInput,
            }
            axios.get('/process/ecode_login.php?act=bing_phone_vent',
            {params:params}).then(data => {
                console.log(data.data)
                let { msg, code} = data.data
                    if (code != 200) {
                       
                        return false;
                    } else {
                        return true;
                    }
                }).catch(function (error) { 
                    console.log(error); 
            });
        },
        //获取code然后跳去接口登录
        getWxlogin(){
            sessionStorage.setItem('logo','1')
            let params={
                Scode:this.Scode,
                wxinfo:this.wxinfo,
            }
            axios.post('/process/ecode_login.php?act=ecode_go',
            Qs.stringify(params)).then(data => {
                console.log(data.data)
                let { msg, code} = data.data
                    if (code !== 200) {
                        window.vant.Toast.fail(msg)
                    } else {
                        data = data.data
                        if(data.msg!="登录成功"){
                            this.isShow=true
                            //绑定手机号弹出手机号和验证码
                            this.Openid=data.data.Openid
                            if(data.data.Unionid){
                                this.Unionid=data.data.Unionid
                            }else{
                                this.Unionid=''
                            }
                            this.session_code=data.data.session_code
                        }else{
                            this.isSuccess=true
                            this.isShow=false
                        }
                    }
                }).catch(function (error) { 
                    console.log(error); 
            });
        },
        //绑定手机号跳转首页
        bingPhone(){
            let from = {
                    phone:this.from1.phone,
                    sms_code: this.from1.sms_code,
                    openid:this.Openid,
                    session_code:this.session_code,
                    Unionid:this.Unionid
                }
            from =JSON.stringify(from)
            let sign=md5(from)
            let params={
                from:from,
                sign:sign
            }
            axios.post('/process/ecode_login.php?act=bing_phone',
                Qs.stringify(params)).then(data => {
                let { msg, code} = data.data
                    if (code != 200) {
                        window.vant.Toast.fail(msg)
                    } else {
                        //window.vant.Toast("绑定成功,自动登录")
                        this.isSuccess=true
                        this.isShow=false
                    }
                }).catch(function (error) { 
                    console.log(error); 
            });
        }
    }  
})
</script>
</html>